<template>
    <div>
        <el-card class="box-card">
            <div slot="header">
                <!-- 表单搜索操作栏 -->
                <el-form :inline="true" :model="search" class="demo-form-inline" size="mini">

                 

                    <el-form-item>
                        <el-input v-model="search.name" placeholder="关键字"></el-input>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" @click="getTableData">查询</el-button>
                    </el-form-item>
                    <el-form-item >
                          <el-select placeholder="请选择状态" v-model="zt">
      <el-option :label="item.name"  v-for="(item,index) in xlk"  :key="index" :value="item.id"></el-option>
    </el-select>
                    </el-form-item>
                </el-form>
            </div>

            <!-- 表格数据 -->
            <el-table ref="multipleTable" :data="tableData" v-loading="loading" tooltip-effect="dark"
                style="width: 100%" >

                <el-table-column type="expand">
                    <template #default="scope">
                        <el-col :span="8" v-for="item in scope.row.GoodPropertyKey" :key="item.GPKID">
                            {{ item.Name }}
                            <ul>
                                <li v-for="pp in item.GoodPropertyValue" :key="pp.GPVID">
                                     <el-avatar :src="imgbase +scope. row.Images"></el-avatar> {{ pp.Value }}</li>
                            </ul>
                        </el-col>
                    </template>
                </el-table-column>

                
                <el-table-column prop="GID" label="编号" width="55">
                </el-table-column>

                <el-table-column prop="Images" label="图片">
                    <template #default="{ row }">
                        <el-avatar :src="imgbase + row.Images"></el-avatar>
                    </template>
                </el-table-column>

                <el-table-column prop="Name" label="商品" >
                    <template #default="{ row }">
                        <div v-html="highlight(row.Name)"></div>
                    </template>
                </el-table-column>

                <el-table-column prop="Content" label="描述" show-overflow-tooltip>
                    <template #default="{ row }">
                        <div v-html="highlight(row.Content)"></div>
                    </template>
                </el-table-column>

                <el-table-column prop="Price" label="价格" >
                </el-table-column>

                <el-table-column prop="TypeName" label="类型" >
                </el-table-column>


                <el-table-column prop="Use_Property" label="规格" >
                    <template #default="{ row }">
                        <!-- @change="" -->
                        <el-switch v-model="row.Use_Property" :active-value="true" :inactive-value="false">
                        </el-switch>

                    </template>
                </el-table-column>


                <el-table-column label="操作" width="220">
                    <template #default="{ row }">
                        <!-- 删除气泡提示 -->
                      
                        &nbsp;
                        <el-button type="warning" size="mini" @click="edit(row)">商品详情</el-button>
                      
                    </template>
                </el-table-column>
            </el-table>
            <br>
            <!-- 分页 -->
            <el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange"
                :hide-on-single-page="autoHide" :page-sizes="[5, 10, 20, , 50, 100]" :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="totalNum" background>
            </el-pagination>

        </el-card>


        


        <!-- 修改的弹窗 -->
        <el-dialog  append-to-body width="500px"  top="5vh" :visible.sync="editDialogFormVisible" >
            <edit v-model="editDialogFormVisible" :editData="editData" @refresh="getTableData"></edit>
        </el-dialog>


    </div>
</template>

<script>
import basepath from '../../plugins/base.js'

import edit from './edit.vue'

export default {
    name: 'goods',
    data() {
        return {
            imgbase: '',
            loading: false,
            pageIndex: 1,  //当前的 页码
            pageSize: 5,   //每页条数
            totalNum: 0,   //总数量
            autoHide: false,  //当只有一页数据时是否隐藏分页
            search: {
                name: ''
            },
            tableData: [],    //数据
           //选中的数据
            editData: {},
            //控制添加弹窗
            createDialogFormVisible: false,
            editDialogFormVisible: false,
            sjj:false,
            xjj:true,
            xlk:[{id:1,name:'上架'},{id:2,name:'下架'}],
            zt:1
        }
    },
    methods: {
        //获取数据data
        getTableData() {
            this.loading = true;
            this.axios({
                method: 'get',
                url: 'Goods/Page',
                params: { page: this.pageIndex, limit: this.pageSize, name: this.search.name },
                data: {}
            }).then(response => {
                console.log('response: ', response);
                this.tableData = response.data.filter(n=>n.On_sale==true);
                this.totalNum = response.count;
                setTimeout(() => {
                    this.loading = false;
                }, 200);
            })
        },
         XgetTableData() {
            this.loading = true;
            this.axios({
                method: 'get',
                url: 'Goods/Page',
                params: { page: this.pageIndex, limit: this.pageSize, name: this.search.name },
                data: {}
            }).then(response => {
                console.log('response: ', response);
                this.tableData = response.data.filter(n=>n.On_sale==false);
                this.totalNum =4;
                setTimeout(() => {
                    this.loading = false;
                }, 200);
            })
        }
        //复选框选中
        
        //分页
        , handleCurrentChange(val) {
            this.pageIndex = val;
            this.getTableData();
        }
        //切换每页数量
        , handleSizeChange(val) {
            this.pageSize = val;
            this.getTableData();
        }

        //添加
        , add() {
            this.createDialogFormVisible = true;
        }
        //修改
        , edit(row) {
            let data = JSON.parse(JSON.stringify(row));
            /*
            //规格
            let property = [
                {
                    GSKID: 1,  //规格 主键表  GoodSpecKey  id
                    GoodPropertyValue: [],
                    checked: false
                },
                {
                    GSKID: 2,
                    GoodPropertyValue: [],
                    checked: false
                },
                {
                    GSKID: 3,
                    GoodPropertyValue: [],
                    checked: false
                }
            ]
            data.GoodPropertyKey.forEach(key => {
                let pp = property.filter(v => v.GSKID == key.GSKID)[0];
                pp.checked = true;
                key.GoodPropertyValue.forEach(v => {
                    pp.GoodPropertyValue.push(v.GSVID);
                })
            })

            data.GoodPropertyKey = property;
            */
            this.editData = data;
            //处理
            this.editDialogFormVisible = true;
        }

        //删除
        
     
        
        //文字搜索 高亮效果
        , highlight(v) {
            return v.replace(this.search.name, '<span class="highlight">' + this.search.name + '</span>')
        }
    },
    created() {
        this.imgbase = basepath.imgUrl;
        this.getTableData();
    },
    components: {
        edit
    },
    watch:{
        zt(newvalue,oldvalue){
            console.log(newvalue)
           if(newvalue==2){
             this.XgetTableData();
             this.sjj=true;
             this.xjj=false;
           }else{
               this.getTableData();
               this.xjj=true;
               this.sjj=false;
           }
        }
    }
    
}
</script>

<style>
.highlight {
    font-weight: 600;
    font-size: 16px;
    color: #ffffff;
    animation: glow 666ms infinite alternate;
}

@keyframes glow {
    form {
        text-shadow:
            0 0 10px #1877f2,
            0 0 20px #1459b3,
            0 0 30px #179bff;
    }


    to {
        text-shadow:
            0 0 5px #1877f2,
            0 0 10px #1459b3,
            0 0 15px #179bff;
    }
}

.demo-form-inline .el-form-item {
    margin-bottom: 0px;
}

</style>